<link href="<?php echo base_url('theme/css/frontend/company-add.css'); ?>" rel="stylesheet">
<link href="<?php echo base_url('theme/css/frontend/account-manager.css'); ?>" rel="stylesheet">
<script src="<?php echo base_url('theme/js/frontend/jquery.trialPhoto.js'); ?>" type="text/javascript"></script>
<script src="<?php echo base_url('theme/js/frontend/jquery.ajax.upload.js'); ?>"></script>
<script src="<?php echo base_url('theme/js/frontend/jquery.validate.js'); ?>"></script>
<link href="<?php echo base_url(); ?>theme/third_party/jQueryTagging/styles/token-input.css" rel="stylesheet">
<link href="<?php echo base_url(); ?>theme/third_party/jQueryTagging/styles/token-input-facebook.css" rel="stylesheet">
<script src="<?php echo base_url(); ?>theme/third_party/jQueryTagging/src/jquery.tokeninput.js" type="text/javascript"></script>
<link href="<?php echo base_url('theme/css/frontend/jquery-ui.css'); ?>" type="text/css" rel="stylesheet" />
<script type="text/javascript">
    $(document).ready(function() {
        var upload = new AjaxUpload('#banner_large', {
            //upload script
            action: '/event/ajaxUpload',
            onSubmit: function(file, extension) {
                //check file extension
                if (!(extension && /^(jpg|png|jpeg|gif)$/.test(extension))) {
                    // extension is not allowed
                    $("<span class='error'>Error: Not a valid file extension</span>").appendTo("#file_holder #errormes");
                    // cancel upload
                    return false;
                } else {
                    // get rid of error
                    $('.error').hide();
                }
                //send the data
                upload.setData({
                    'file': file
                });
            },
            onComplete: function(file, response) {
                //This lower portion gets the error message from upload.php file and appends it to our specifed error message block
                //find the div in the iFrame and append to error message
                var oBody = $(".iframe").contents().find("div");
                //add the iFrame to the errormes td
                $(oBody).appendTo("#errormes");
                var oBody2 = $(".iframe").contents().find("input");
                //add the iFrame to the errormes td
                $(oBody2).appendTo("#errormes");
                if ($(".success").last().text() != "") {
                    $("#banner_large_append").html('<img src="' + $(".success").last().text() + '" />');
                }
            }
        });
        $('#time_event').datetimepicker({
            dateFormat: 'yy/mm/dd',
            timeFormat: "hh:mm:ss"
        });
        $("#dialog-confirm").dialog({
            resizable: false,
            autoOpen: false,
            modal: true,
            buttons: {
                "Huỷ bỏ sự kiện": function() {
                    window.location = "/event/delete/<?php echo $event['id']; ?>";
                },
                "Không huỷ bỏ": function() {
                    $(this).dialog("close");
                }
            }
        });

        $("#invite_check").tokenInput("/event/alluser", {
            prePopulate: <?php if (isset($json) && $json != "") {
    echo $json;
} else {
    echo "''";
} ?>,
            theme: "facebook",
            preventDuplicates: true
        });
    });

    function cancel() {
        document.getElementById('form-info').reset();
        $("label[class=error]").hide();
    }

    function cancelevent(id) {
        var r = confirm("Bạn có chắc chắn muốn huỷ sự kiện này?");
		if (r == true) {
			window.location = "/event/delete/" + id;
		}
    }
</script>
<div class="management-container booth-container" style="margin-top: 40px;">
<?php echo validation_errors('<div class="alert alert-error">', '</div>'); ?>
    <h3 style="color:black;">Vị trí quảng cáo</h3>
    <hr class="hr" />

    <div class="management-wrapper">
        <div style="min-height:65px;">
            <button class="btn btn-primary btn-event" style="width:200px" type="button" onclick="window.location = '/event/company';">
                Tạo sự kiện doanh nghiệp
            </button>
            <button class="btn btn-event" style="width:200px" type="button" onclick="window.location = '/event/booth';">
                Tạo sự kiện gian hàng
            </button>
            <button class="btn btn-event" type="button" onclick="window.location = '/event/';">
                Quản lý sự kiện
            </button>
        </div>
        <hr class="hr" />
        <div class="management-block">
            <form method="post" id=form-info class="form-horizontal" action=<?php echo base_url('/event/company'); ?> enctype=multipart/form-data >
                <div class="info-event">
                    <div class="event-left">
                        <?php
                        if (isset($event['id'])) {
                            ?>
                            <input type="hidden" name="id" value="<?php echo set_value('id', $event['id']); ?>" />
    <?php
}
?>
                        <div name="participation_name" style="display:none"><?php echo set_value('participation_name', $user_id); ?></div>
                        <input type="hidden" name="invite" value="" />
                        <div class="control-group">
                            <label for="name" class="control-label-event">Tên sự kiện<i>*</i></label>
                            <div class="controls-event">
                                <input type=text name=name id=name class="input-xxlarge-event" value="<?php echo set_value('name', $event['name']); ?>">
                            </div>
                        </div>                        
                        <div class="control-group">
                            <label for="address" class="control-label-event">Địa điểm<i>*</i></label>
                            <div class="controls-event">
                                <input type=text name=address id=address class="input-xxlarge-event" value="<?php echo set_value('address', $event['address']); ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="address" class="control-label-event">Thời gian<i>*</i></label>
                            <div class="controls-event">
                                <input type=text name=time_event id=time_event class="input-xxlarge-event" value="<?php echo set_value('time_event', $event['time_event']); ?>"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="content" class="control-label-event">Chi tiết<i>*</i></label>
                            <div class="controls-event">
                                <textarea name=content id=content class="input-xxlarge-event"><?php echo set_value('content', $event['content']); ?></textarea>
                            </div>
                        </div>
                        <!--<div class="control-group">
                            <label for="tax_code" class="control-label-event">Mời bạn bè</label>
                            <div class="controls-event">
                                <input type=text name=invite_check id=invite_check class="input-xxlarge-event" value="">
                            </div>
                        </div>-->
                        <div class="control-group">
                            <div class=controls-event>
                                <button class="btn btn-primary btn-event" type=submit name=event-submit value="Lưu thay đổi">
                                    Lưu thay đổi
                                </button>
<?php
if (isset($event['id']) && $event['id'] != "") {
    ?>	
                                    <button class="btn btn-event-cancel" type="button" onclick="cancelevent(<?php echo $event['id']; ?>);">
                                        Hủy bỏ
                                    </button>
    <?php
} else {
    ?>
                                    <button class="btn btn-event-cancel" type="button" onclick="cancel();">
                                        Clear
                                    </button>
    <?php
}
?>
                            </div>
                        </div>
                    </div>
                    <div class="event-right">
                        <div style="position: relative;">
                            <div id="banner_large_append">
                                <?php if ($event['image']): ?>
                                    <img src="<?php echo base_url($event['image']); ?>" />
<?php else: ?>
                                    <img src="<?php echo base_url('theme/images/sample/event/340x184.jpg'); ?>" />
<?php endif; ?>
                            </div>
                            <div class="file-upload-wrapper">
                                <input class="file-upload" type="file" id="banner_large" name="image" />
                                Thay đổi banner
                            </div>
                            <button type="submit" class="submit_btn" style="display:none;">
                                Upload Files
                            </button>
                        </div>
                        <div id="errormes"></div>
                    </div>

                    <script src="<?php echo base_url('theme/js/frontend/jquery.Jcrop.min.js'); ?>"></script>
                    <script src="<?php echo base_url('theme/js/frontend/jquery.json-2.4.min.js'); ?>"></script>
                    <script src="<?php echo base_url('theme/js/frontend/filedrag.js'); ?>"></script>
                </div>
            </form>
            <div id="dialog-confirm" title="Huỷ bỏ sự kiện?">
                <p>
                    <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
                    Bạn có chắc chắn muốn huỷ bỏ sự kiện này?
                </p>
            </div>
        </div>
    </div>
    <!-- /management-wrapper -->
</div>
<!-- /management-container -->
<script type="text/javascript">
    $(document).ready(function() {
        // validate form on keyup and submit
        $("#form-info").validate({
            ignore: "",
            rules: {
                name: {
                    required: true
                },
                content: {
                    required: true
                },
                address: {
                    required: true
                },
                time_event: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: 'Bạn cần nhập Tên sự kiện'
                },
                content: {
                    required: 'Bạn cần nhập Chi tiết'
                },
                address: {
                    required: 'Bạn cần nhập Địa điểm',
                },
                time_event: {
                    required: 'Bạn cần nhập Thời gian'
                }
            },
            submitHandler: function(form) {
                $("input[name=invite]").val($("input[name=invite_check]").val());
                form.submit();
            }
        });
        // end validate
    });
</script>
</div>